
package http;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.fluent.Response;

public class HttpClientTest {
	
	
	public static void main(String[] args) throws ClientProtocolException, IOException, URISyntaxException {
		
		
		String url = "http://localhost:8080/CooperateWeb/LoginServlet?id=10";
		
		final Response execute = Request.Get(url).execute();
		
		HttpResponse returnResponse = execute.returnResponse();
		
		Header[] lastHeader = returnResponse.getHeaders("Set-Cookie");
		
		String id = null;
		
		for (Header header : lastHeader) {
			HeaderElement[] elements = header.getElements();
			
			for (HeaderElement headerElement : elements) {
		    System.out.println(headerElement.getName());
		    id = headerElement.getValue();
		    System.out.println("id: "+id);
	    }
    }
		
		Desktop.getDesktop().browse(new URI("http://localhost:8080/CooperateWeb/suinos/pda/formPDA.xhtml"+";jsessionid="+id));
		
  }

}
